import { Component, OnInit } from '@angular/core';

// 引入Onvif相关接口
import {OnvifWsService} from '../onvif-ws.service';

@Component({
  selector: 'app-device-dns',
  templateUrl: './device-dns.component.html',
  styleUrls: ['./device-dns.component.css']
})
export class DeviceDnsComponent implements OnInit {

  // 注入OnvifWsService实例
  constructor(private ws: OnvifWsService) { }

  // 设备信息
  deviceInfo = {
    IPv4: '',
    Gateway: '',
    PreferredDNS: '',
    AlternativeDNS: ''
  };

  ngOnInit() {
    // 获取设备网络信息
    this.ws.getNetworkInterfaces(info => {
      this.deviceInfo.IPv4 = info['s:Envelope']
        ['s:Body'][0]['tds:GetNetworkInterfacesResponse'][0]['tds:NetworkInterfaces'][0]
        ['tt:IPv4'][0]['tt:Config'][0]['tt:FromDHCP'][0]['tt:Address'][0];
    });

    // 获取设备网关信息
    this.ws.getNetworkDefaultGateway(info => {
      this.deviceInfo.Gateway = info['s:Envelope']['s:Body'][0]['tds:GetNetworkDefaultGatewayResponse'][0]
        ['tds:NetworkGateway'][0]['tt:IPv4Address'][0];
    });

    // 获取设备DNS信息
    this.ws.getDNS(info => {
      this.deviceInfo.PreferredDNS = info['s:Envelope']['s:Body'][0]['tds:GetDNSResponse'][0]
        ['tds:DNSInformation'][0]['tt:DNSFromDHCP'][0]['tt:IPv4Address'][0];

      this.deviceInfo.AlternativeDNS = info['s:Envelope']['s:Body'][0]['tds:GetDNSResponse'][0]
        ['tds:DNSInformation'][0]['tt:DNSFromDHCP'][1]['tt:IPv4Address'][0];
    });

  }
}
